﻿CREATE FUNCTION [dbo].[fn_TableExists]
(
	@Table sysname
)
RETURNS BIT
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	DECLARE @Object sysname; SET @Object = PARSENAME(@Table, 1)
	DECLARE @Schema sysname; SET @Schema = ISNULL(PARSENAME(@Table, 2), 'dbo')
	
	IF EXISTS (
	       SELECT *
	       FROM   sys.tables t
	       WHERE  t.[name] = @Object
	              AND t.[type] = 'U'
				  AND schema_name(t.schema_id) = @Schema
	   )
	    RETURN @True
	
	RETURN @False
END